package com.myx.design.single.realization;

/**
 * 描述:单例模式-双重锁
 * @author: myx
 * @date: 2018/11/28
 * Copyright © 2018-hotpot. All rights reserved.
 */
public class UserSingleDoubleLock {
    private static UserSingleDoubleLock userSingleDoubleLock;
    private UserSingleDoubleLock(){}
    //重排序(多线程才会出现)会出现创建多次
    public static UserSingleDoubleLock getInstance(){
        if(userSingleDoubleLock==null){
            synchronized (UserSingleDoubleLock.class){
                if(userSingleDoubleLock==null){
                    //这里会有重排序问题
                    userSingleDoubleLock=new UserSingleDoubleLock();
                }
            }
        }
        return userSingleDoubleLock;
    }
    public static void main(String[] args) {
        System.out.println(UserSingleDoubleLock.getInstance()==UserSingleDoubleLock.getInstance());
    }
}
